
{extend name="public:common_edit"/}
{block name="css"}
<link  type="text/css" rel="stylesheet" href="__TIMEPICKER__/bootstrap-datetimepicker.min.css" />
<style>
    .form-control {
        max-width: 350px;
    }

    .tb-name {
        width: 238px;
    }
    .error{
        color: red;
        margin-top: 10px;
        display: none;
    }
    .select{
        margin-bottom: 10px;
    }
    .doctor{
        display: none;
    }
</style>
{/block}
{block name="main"}
<section class="content">
    <div class="container-fluid">
        <div class="pull-right">
            <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default"
               data-original-title="返回"><i class="fa fa-reply"></i></a>
            <a href="javascript:void(0);" class="btn btn-default"
               data-url="javascript:;"
               onclick="get_help(this)"><i class="fa fa-question-circle"></i> 帮助</a>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-list"></i> {$title}</h3>
            </div>
            <div class="panel-body">
                <!--表单数据-->
                <form action="" method="post" class="form-horizontal"
                      id="category_form">

                    <!--通用信息-->
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab_tongyong">
                            <table class="table table-bordered">
                                <tbody>
                                <tr>
                                    <td>封面缩略图:</td>
                                    <td>{:uploadHtml('img',$data.img,'single_img')}</td>
                                </tr>
                                <tr>
                                    <td>活动名称:</td>
                                    <td><input placeholder="活动名称" class="form-control" name="title" type="text" value="{$data.title}"></td>
                                </tr>

                                <tr id="game">
                                    <td>排序:</td>
                                    <td>
                                        <input placeholder="排序" class="form-control" name="sort" type="text" value="{$data.sort}">
                                    </td>
                                </tr>

                                <tr>
                                    <td>活动开始日期:</td>
                                    <td><input type="text" name="start_time" value="{$data.start_time}" placeholder="活动开始时间" class="form-control timepicker"></td>
                                </tr>
                                <tr>
                                    <td>活动结束日期:</td>
                                    <td><input type="text" name="end_time" value="{$data.end_time}" placeholder="活动结束日期" class="form-control timepicker"></td>
                                </tr>

                                <tr>
                                    <td>详情:</td>
                                    <td><textarea name="content" id="editor" style="width: 900px;height: 500px">{$data.content}</textarea></td>
                                </tr>

                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="pull-right">
                        <label class="control-label col-sm-2"></label>
                        <input type="hidden" name="id" value="{$data.id}">
                        <input class="btn btn-primary submit" type="submit" value="保存">
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
{/block}
{block name="js"}
<script src="__TIMEPICKER__/bootstrap-datetimepicker.js?{$stamp}"></script>
<script src="__TIMEPICKER__/bootstrap-datetimepicker.zh-CN.js?{$stamp}"></script>
<script type="text/javascript" src="https://unpkg.com/qiniu-js@v2.4.0/dist/qiniu.min.js"></script>
<link rel="stylesheet" href="/public/admin/ueditor/themes/default/css/ueditor.min.css">
<script type="text/javascript" src="/public/admin/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/public/admin/ueditor/ueditor.all.js"></script>
<script>
    $(function () {
        var ue = UE.getEditor('editor');

        //防止事件冒泡
        $(document).delegate('.timepicker','focusin', function(){
            $('.timepicker').datetimepicker({
                format: 'yyyy-mm-dd',
                minView: "month",
                language:  'zh-CN',
                weekStart: 1,
                todayBtn:  0,
                autoclose: 1,
                startDate:'2015-01-01',
                maxView:3,
                endDate:0,
                todayHighlight: 1,
                startView: 2,
                forceParse: 0,
                showMeridian: 1
            });
        });
    });
    $('#file').change(function () {
        var file = $('#file')[0].files[0];
        if (!file){
            layer.msg('您未选择文件', {icon: 5, time: 2000});return false;
        }
        var btn = $(this);
        btn.attr('disabled', 'disabled');
        layer.msg('上传中', {
            icon: 16
            ,shade: [0.3,'#999999'],
            time:21600000
        });
        var token = "{$token}";
        var index = file.name.lastIndexOf(".");
        var ext = file.name.substring(index);
        var key = takeName('vod',2)+ext;
        var config = {
            useCdnDomain: true,
            region: qiniu.region.z0,
            concurrentRequestLimit:3,
        };
        var putExtra = {
            fname: file.name,
            params: {},
            mimeType:  null
        };
        var observer = {
            next(res){
                $('.layui-layer-padding').html('<i class="layui-layer-ico layui-layer-ico16"></i>上传中 '+res.total.percent.toFixed(2)+'%');
            },
            error(err){
                layer.msg('上传失败,请稍后重试'+err.message, {icon: 5, time: 2000});
                layer.closeAll("loading");
                btn.attr('disabled', false);
            },
            complete(res){
                var domain = "{$domain}";
                var url = domain+res.key;
                $('.del').attr('data-url',url);
                $("input[name='img']").val(url);
                layer.msg('上传成功', {icon: 1, time: 2000});
                layer.closeAll("loading");
                btn.attr('disabled', false);
                removeFile('file');
            }
        };
        var observable = qiniu.upload(file, key, token, putExtra, config)
        var subscription = observable.subscribe(observer)

    });


    $('.del').click(function () {
        var btn = $(this);
        btn.attr('disabled', 'disabled');
        var load=layer.load(1, {
            shade: [0.3,'#999999'] //0.1透明度的白色背景
        });
        var url = $(this).data('url');
        $.get("{:url('/upload/delete1')}"+'?file='+url, function(result){
            if (result.code == 1){
                layer.msg('删除成功', {icon: 1, time: 2000});
                layer.closeAll("loading");
                btn.attr('disabled', false);
                $('.del').attr('data-url','');
                $("input[name='img']").val('');
            } else{
                layer.msg('删除失败,请稍后重试', {icon: 5, time: 2000});
                layer.closeAll("loading");
                btn.attr('disabled', false);
            }
        });

    })

</script>

{/block}